"""
装饰器： 不改变函数原有实现，给函数添加新功能
"""
import time


# def center():
#     username = input("输入用户名")
#     password = input("输入密码")
#     if username == "admin" and password == "123456":
#         print(f"欢迎来到个人中心")
#     else:
#         print(f"登录失败")
# center()
#
#
# def cart():
#     username = input("输入用户名")
#     password = input("输入密码")
#     if username == "admin" and password == "123456":
#         print(f"欢迎来到购物车")
#     else:
#         print(f"登录失败")
#
# cart()


# def center():
#     print(f"欢迎来到个人中心")
#
# def cart():
#     print(f"欢迎来到购物车")
#
# def userinfo():
#     print(f"欢迎获取用户信息")
#
# # 闭包： 1. 外部函数嵌套内部函数  2.外部函数将内部函数返回 3.内部函数可以访问外部函数局部变量
# def login_required(f):
#     def check():
#         name = input("输入用户名")
#         passwrod = input("输入密码")
#         if name == "admin" and passwrod == "123456":
#             f()
#         else:
#             print(f"登录失败")
#     return check
#
# center = login_required(center)
# center()
#
# cart = login_required(cart)
# cart()
#
# userinfo = login_required(userinfo)
# userinfo()


# 闭包： 1. 外部函数嵌套内部函数  2.外部函数将内部函数返回 3.内部函数可以访问外部函数局部变量
# def login_required(f):
#     def check():
#         name = input("输入用户名")
#         passwrod = input("输入密码")
#         if name == "admin" and passwrod == "123456":
#             f()
#         else:
#             print(f"登录失败")
#     return check
#
#
# @login_required
# def center():
#     print(f"欢迎来到个人中心")
#
# @login_required
# def cart():
#     print(f"欢迎来到购物车")
#
# @login_required
# def userinfo():
#     print(f"欢迎获取用户信息")
#
#
# center()
#
# cart()
#
# userinfo()


# def cost_time(f):
#     def calc():
#         start = time.time()
#         f()
#         end = time.time()
#         print(f"{f.__name__}时间开销{end-start}")
#     return calc
#
#
# @cost_time
# def method1():
#     # 使用冒泡排序完成降序
#     l = [i for i in range(1, 1000)]
#     for i in range(len(l) - 1):
#         for j in range(i + 1, len(l)):
#             if l[i] < l[j]:
#                 temp = l[i]
#                 l[i] = l[j]
#                 l[j] = temp
#     # print(l)
#
#
# # method1()
# # method1 = cost_time(method1)
# method1()
#
#
# @cost_time
# def method2():
#     # 使用选择排序完成降序
#     l = [i for i in range(1, 1000)]
#     for i in range(len(l) - 1):
#         max_index = i
#         for j in range(i + 1, len(l)):
#             if l[j] > l[max_index]:
#                 max_index = j
#         if max_index != i:
#             temp = l[i]
#             l[i] = l[max_index]
#             l[max_index] = temp
#     # print(l)
#
#
# # method2 = cost_time(method2)
# method2()


